package pers.cz.service.impl;

import pers.cz.business.AutoTestCaseBusiness;
import pers.cz.model.*;
import pers.cz.piny.PinyUtil;
import pers.cz.pub.BeanHelper;
import pers.cz.service.AutoTestCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: PostGirl-panent
 * @description: AutoTestCaseServiceImpl
 * @author: Cheng Zhi
 * @create: 2021-11-10 19:06
 **/
@Service
public class AutoTestCaseServiceImpl implements AutoTestCaseService {

    @Autowired
    BeanHelper beanHelper;

    @Override
    public List<AutoTestCase> queryAllAutoTestCaseByPage(Integer pageStart, Integer pageLimit) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryAllAutoTestCaseByPage(pageStart, pageLimit);
    }

    @Override
    public Integer qeuryCount() {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryCount();
    }

    @Override
    public Integer addAutoTestCase(AutoTestCase autoTestCase) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addAutoTestCase(autoTestCase);
    }

    @Override
    public Integer updateAutoTestCase(AutoTestCase autoTestCase) {
        return null;
    }

    @Override
    public Integer deleteAutoTestCase(Integer id) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.deleteAutoTestCase(id);
    }

    @Override
    public List<AutoTestCase> selectAutoTestCaseByFuzzy(String caseName) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.selectAutoTestCaseByFuzzy(caseName);
    }

    @Override
    public Long getSoNbr() {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.getAutoTestCaseId();
    }

    @Override
    public Integer addTestCaseParams(AutoTestCaseParams autoTestCaseParams, AutoTestCaseParamsSql autoTestCaseParamsSql, AutoTestCaseParamsCode autoTestCaseParamsCode, AutoTestCaseParamsRegular autoTestCaseParamsRegular) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addAutoTestCaseParams(autoTestCaseParams, autoTestCaseParamsSql, autoTestCaseParamsCode, autoTestCaseParamsRegular);
    }

    @Override
    public Integer addTestCaseCheck(AutoTestCaseCheck autoTestCaseCheck) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addAutoTestCaseChecks(autoTestCaseCheck);
    }

    @Override
    public Integer addPublicParams(AutoPublicParams autoPublicParams) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addAutoPublicParams(autoPublicParams);
    }

    @Override
    public Integer deleteAutoTestCaseBatch(List<Integer> ids) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.deleteAutoTestCaseBatch(ids);
    }

    @Override
    public List<AutoTestCaseCheck> queryAutoTestCaseCheckByTestCaseId(Integer testCaseId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryAutoTestCaseCheckByTestCaseId(testCaseId);
    }

    @Override
    public Integer updateAutoTestCaseCheck(AutoTestCaseCheck autoTestCaseCheck) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateAutoTestCaseCheck(autoTestCaseCheck);
    }

    @Override
    public List<AutoTestCaseParams> queryAutoTestCaseParams(Integer testCaseId) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryAutoTestCaseParams(testCaseId);
    }

    @Override
    public List<AutoPublicParams> queryAutoPublicParams(Integer testCaseId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryAutoPublicParams(testCaseId);
    }

    @Override
    public Integer updateAutoTestCaseParams(AutoTestCaseParams autoTestCaseParams) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateAutoTestCaseParams(autoTestCaseParams);
    }

    @Override
    public Integer updateAutoPublicParams(AutoPublicParams autoPublicParams) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateAutoPublicParams(autoPublicParams);
    }

    @Override
    public Integer deleteAutoTestCaseCheckById(Integer id) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.deleteAutoTestCaseCheck(id);
    }

    @Override
    public Map<Integer, List<String>> selectAllIdAndCaseName() {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);

        List<AutoTestCase> testCaseList = business.queryAllAutoTestCase();
        Map<Integer, List<String>> map = new HashMap<>();
        Map<String, Object> map1 = new HashMap();
        for (AutoTestCase testCase : testCaseList) {
            List<String> list = new ArrayList<>();
            try {
                String caseName = testCase.getCaseName();
                list.add(caseName);
                list.add(PinyUtil.getPingYin(caseName));
                map.put(testCase.getId(),list);
            } catch (Exception e) {

            }
        }

        return map;
    }

    @Override
    public Integer saveCode(AutoTestCaseParamsCode autoTestCaseParamsCode) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.saveCode(autoTestCaseParamsCode);
    }

    @Override
    public Integer saveSqlCode(AutoTestCaseParamsSql autoTestCaseParamsSql) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.saveSqlCode(autoTestCaseParamsSql);
    }

    @Override
    public Integer updateCode(AutoTestCaseParamsCode autoTestCaseParamsCode) {

        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateCode(autoTestCaseParamsCode);
    }

    @Override
    public Integer updateSqlCode(AutoTestCaseParamsSql autoTestCaseParamsSql) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateSqlCode(autoTestCaseParamsSql);
    }

    @Override
    public AutoTestCaseParamsCode queryCode(Integer paramId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.queryCode(paramId);
    }

    @Override
    public AutoTestCaseParamsSql querySqlCode(Integer paramId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.querySqlCode(paramId);
    }

    @Override
    public Integer deleteSqlTemplateById(Integer sqlTemplateId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.deleteSqlTemplateById(sqlTemplateId);
    }

    @Override
    public Integer updateSqlTemplate(AutoCollectTestCaseSql autoCollectTestCaseSql) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateSqlTemplate(autoCollectTestCaseSql);
    }

    @Override
    public Integer addSqlTemplate(AutoCollectTestCaseSql autoCollectTestCaseSql) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addSqlTemplate(autoCollectTestCaseSql);
    }

    @Override
    public Integer addAutoCheckSqls(List<AutoTestCaseCheckSql> autoTestCaseCheckSqls) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addCheckSqls(autoTestCaseCheckSqls);
    }

    @Override
    public Integer addAutoCheckSql(AutoTestCaseCheckSql autoTestCaseCheckSql) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.addCheckSql(autoTestCaseCheckSql);
    }

    @Override
    public List<AutoTestCaseCheckSql> findChcekSqlsByTestCaseId(Integer testCaseId) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.findChcekSqlsByTestCaseId(testCaseId);
    }

    @Override
    public int updateChcekSql(AutoTestCaseCheckSql autoTestCaseCheckSql) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateChcekSql(autoTestCaseCheckSql);
    }

    @Override
    public Integer deleteCheckSqlById(Integer id) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.deleteCheckSqlById(id);
    }

    @Override
    public Integer updateRegularExpr(AutoTestCaseParamsRegular autoTestCaseParamsRegular) {
        AutoTestCaseBusiness business = new AutoTestCaseBusiness();
        business.setMapper(beanHelper);
        return business.updateRegularExpr(autoTestCaseParamsRegular);
    }
}
